package com.byl.mvvm.ui.viewmodel

import android.os.SystemClock
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.byl.mvvm.ui.common.model.User
import kotlin.concurrent.thread

/**
 *
 * @ProjectName:    MVVM
 * @Package:        com.byl.mvvm.ui.viewmodel
 * @ClassName:      UserViewModel
 * @Description:
 * @Author:  lirui441
 * @CreateDate:     2020/9/4 0004 上午 10:00
 */
class UserViewModel : ViewModel(){
//    var user = User("张三",10,"地址")
    var userData: MutableLiveData<User> = MutableLiveData()
    init {
       userData.value = User("张三",12,"地址")

        thread {
            SystemClock.sleep(3000)
            userData.value!!.name="李四"
            userData.postValue(userData.value)
        }.start()
    }

    override fun onCleared() {
        super.onCleared()
        Log.i("UserViewModel","onCleared：ViewModel 即将销毁")
    }
}